package com.ruoyi.web.controller.edge;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edge.domain.EdgeDevice;
import com.ruoyi.edge.service.IEdgeDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 设备信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/edge/device")
public class EdgeDeviceController extends BaseController
{
    @Autowired
    private IEdgeDeviceService edgeDeviceService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('edge:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(EdgeDevice edgeDevice)
    {
        startPage();
        List<EdgeDevice> list = edgeDeviceService.selectEdgeDeviceList(edgeDevice);
        return getDataTable(list);
    }
    /**
     * 导出设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('edge:device:export')")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EdgeDevice edgeDevice)
    {
        List<EdgeDevice> list = edgeDeviceService.selectEdgeDeviceList(edgeDevice);
        ExcelUtil<EdgeDevice> util = new ExcelUtil<EdgeDevice>(EdgeDevice.class);
        util.exportExcel(response, list, "设备信息数据");
    }

    /**
     * 获取设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('edge:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(edgeDeviceService.selectEdgeDeviceById(id));
    }

    /**
     * 新增设备信息
     */
    @PreAuthorize("@ss.hasPermi('edge:device:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EdgeDevice edgeDevice)
    {
        return toAjax(edgeDeviceService.insertEdgeDevice(edgeDevice));
    }

    /**
     * 修改设备信息
     */
    @PreAuthorize("@ss.hasPermi('edge:device:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EdgeDevice edgeDevice)
    {
        return toAjax(edgeDeviceService.updateEdgeDevice(edgeDevice));
    }

    /**
     * 删除设备信息
     */
    @PreAuthorize("@ss.hasPermi('edge:device:remove')")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(edgeDeviceService.deleteEdgeDeviceByIds(ids));
    }
}
